home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 July
/
EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso
/
earcd
/
dev
/
c
/
asyncio.lha
/
AsyncIO
/
src
/
FGetsLenAsync.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-18
|
1KB
|
86 lines
#include "async.h"
_LIBCALL APTR
FGetsLenAsync( _REG( a0 ) AsyncFile *file, _REG( a1 ) APTR buf,
_REG( d0 ) LONG numBytes, _REG( a2 ) LONG *len )
{
UBYTE *p = ( UBYTE * ) buf;
LONG length = 0;
numBytes -= 2; /* room for \n and \0 */
for( ;; )
{
UBYTE *ptr;
LONG i, count;
ptr = ( UBYTE * ) file->af_Offset;
if( count = file->af_BytesLeft )
{
count = MIN( count, numBytes );
for( i = 0; ( i < count ) && ( *ptr != '\n' ); ++i )
{
*p++ = *ptr++;
}
length += i;
/* Check for valid EOL char */
if( i < count )
{
*p++ = '\n';
++i;
length += 1;
}
file->af_BytesLeft -= i;
file->af_Offset += i;
if( ( i >= numBytes ) || ( *( p - 1 ) == '\n' ) )
{
*p = '\0';
*len = length;
return( buf );
}
numBytes -= i;
}
if( ReadAsync( file, p, 1 ) < 1 )
{
break;
}
--numBytes;
++length;
if( *p++ == '\n' )
{
break;
}
}
*p = '\0';
*len = length;
if( p == ( UBYTE * ) buf )
{
SetIoErr( file->af_Packet.sp_Pkt.dp_Res2 );
return( NULL );
}
return( buf );
}
_CALL APTR
FGetsAsync( _REG( a0 ) AsyncFile *file, _REG( a1 ) APTR buf, _REG( d0 ) LONG numBytes )
{
LONG len;
return( FGetsLenAsync( file, buf, numBytes, &len ) );
}